home *** CD-ROM | disk | FTP | other *** search
/ NetNews Offline 2 / NetNews Offline Volume 2.iso / news / comp / lang / c-part1 / 5633 < prev    next >
Encoding:
Text File  |  1996-08-05  |  2.4 KB  |  99 lines

  1. Path: fig.leba.net!not-for-mail
  2. From: fweaver@leba.net
  3. Newsgroups: comp.lang.c
  4. Subject: Re: fopen not working
  5. Date: 20 Feb 1996 00:40:24 -0500
  6. Organization: LebaNet, Lebanon PA
  7. Sender: fweaver@fig.leba.net
  8. Message-ID: <4gbms8$ocg@fig.leba.net>
  9. NNTP-Posting-Host: fig.leba.net
  10.  
  11.  
  12.                              RE: FOPEN NOT WORKING
  13.                                        
  14.    From: Malcolm Smith <mjsmith@mpx.com.au>
  15.    Reply to: Malcolm Smith
  16.    Date: 16 Feb 1996 07:19:57 GMT
  17.    Organization: Microplex Pty Ltd
  18.    Newsgroups:
  19.           comp.lang.c
  20.    Reply to: newsgroup(s)
  21.    References:
  22.           <4fjnj1$4q@fig.leba.net>
  23.  
  24. fweaver@leba.net wrote:
  25. >
  26. > Good evening to all C programers
  27. >
  28. >    I have a problem I thought someone might be able to shed some light on
  29. > for me. Below is some of the code I wrote for an install program.
  30. >
  31. >
  32. > #include<stdio.h>
  33. > #include<conio.h>
  34. > char buf[125],stwd[110],trwd[110],*pt,*pt1;
  35. > int i,vr,vd;
  36. > FILE *in, *out;
  37. > main()
  38. > {   [snip]
  39. >
  40. >  instlfile("trkr.cf_","trkr.cfg");
  41. >  instlfile("maplvl3.da_","maplvl3.dat");
  42. >  instlfile("atpctrkr.do_","atpctrkr.doc");
  43. >  instlfile("readme.1s_","readme.1st");
  44. >  instlfile("file_id.di_","file_id.diz");
  45. >
  46. >  [snip]
  47. >
  48. >  if((in=fopen(buf,"r"))!=NULL)
  49. >   { do{ fgets(buf,120,in);
  50. >    pt= (char *)strstr(buf,"XXXXX");
  51. >    if(pt!=NULL){ fclose(out); pt=pt+5;if((out=fopen(pt,"w"))==NULL)printf("ER
  52. ROR");
  53.  
  54. ---------
  55. Without testing the code my best guess is that on the first pass
  56. through the program detects the "XXXXX" and hence tries to close
  57. the previous file.  But there isn't one open yet.
  58. ---------
  59.  
  60. FW- I do not think this makes any problem. If the file pointer is null 
  61. FW- fclose will not do anything. The problem with fopen was the new line 
  62. FW- character at the end of the pt string.
  63.  
  64.  
  65.  
  66. >  else{printf("\nInstalling %s",pt);continue; }}
  67. >    fputs(buf,out);
  68. >  }while(feof(in)==0);
  69. >  }
  70. > }
  71.  
  72. >  [snip]
  73. >
  74. > instlfile(char f[15],char s[15])
  75. > { sprintf(buf,"%s%s",stwd,f);
  76. >  if((in=fopen(buf,"rb"))==NULL){close(in);return(0);}
  77.  
  78. ----------
  79. In the above line use fclose() for the corresponding fopen().
  80. ----------
  81.  
  82. FW- Think that might have been a typo, it's changed to fclose().
  83.  
  84. >  if((out=fopen(s,"wb"))!=NULL)printf("\nInstalling %s",s);
  85. >  while((i=fgetc(in))!=EOF){fputc(i,out);}
  86. >  _fcloseall();
  87. > }
  88.  
  89.  
  90.  
  91. >Regards,
  92.  
  93. >Mal
  94.  
  95. Floyd Weaver
  96.  
  97. Internet E-Mail    fweaver@leba.net
  98. Home page          http://www.leba.net/~fweaver
  99.